import axios from '../../utils/request';
/**
 * 模块名: 课程设置
 */

// 创建
interface CreatedType {
  credit: number;
  planPeopleNumber: number;
  desc: string;
  teacher_id: number;
  major_id: number;
  attribute: string;
  name: string;
}
export const courseCreated = (data: CreatedType) => {
  return axios.request({
    url: '/course',
    method: 'post',
    data,
  });
};

// 列表
export interface SearchType {
  page: number;
  limit: number;
  teacher_id?: number | null;
  major_id?: number | null;
  attribute?: string | null;
  name?: string | null;
}
export const courseList = (params: SearchType) => {
  return axios.request({
    url: '/course',
    method: 'get',
    params,
  });
};

// 详情
export const courseDetail = (id: number) => {
  return axios.request({
    url: `/course/${id}`,
    method: 'get',
  });
};

// 更新
export const courseUp = (id: string | number | undefined, data: CreatedType) => {
  return axios.request({
    url: `/course/${id}`,
    method: 'patch',
    data,
  });
};

// 删除
export const courseDel = (id: number) => {
  return axios.request({
    url: `/course/${id}`,
    method: 'delete',
  });
};

export default { courseCreated, courseList, courseDetail, courseUp, courseDel };
